import json
import os
import yaml
from configparser import ConfigParser



def get_json_data(path):
    json_data_path = os.path.abspath(path)
    with open(json_data_path, 'r', encoding='utf-8') as f:
        json_data = json.load(f)
        return json_data
# json_data_path


def get_yaml_data(path):
    yaml_data_path = os.path.abspath(path)
    with open(yaml_data_path, 'r', encoding='utf-8') as f:
        data = yaml.safe_load(f.read())
        return data


def get_ini_data(path):
    cfg = ConfigParser()
    cfg.read(path, encoding='utf-8')
    return dict(cfg.items())


def get_env_info(fields,env_info_path):
    env_info = get_yaml_data(env_info_path)
    field_list = fields.split('.')
    info = env_info
    for field in field_list:
        info = info[field]
    return info

if __name__ == "__main__":
    # data = get_json_data(r'D:\HaierZhiJiaApiTest\HaierZhiJiaApiTest\data\Schedule\test_query_schedule.json')
    # print(data)
    headers = get_env_info("icp.headers","../conf/shengchan_env.yaml")
    print(headers)

